package com.shouhuobao.take.invite;

import android.os.Bundle;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.consts.MsgID;
import com.iseastar.guojiang.logic.AppHttp;
import com.iseastar.guojiang.logic.JSON;
import com.iseastar.guojiang.model.ReqResult;
import com.shouhuobao.station.R;
import com.shouhuobao.take.model.StationInviteHistoryBean;

import droid.frame.view.xlist.SListView;

/**
 * Created by joker on 2017/9/26.
 * 邀请好友开通记录
 */
public class StationInviteHistoryActivity extends BaseActivity2 {

    protected SListView mListView;
    protected StationInviteHistoryAdapter mAdapter = null;
    protected SwipeRefreshLayout mRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showLoadingDialog(null);
        AppHttp.getInstance().queryStationInviteOpenRecord();
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.activity_station_invite_history);
        super.findViewById();
        getAppTitle().setCommonTitle("邀请好友开通记录");
        mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
        mListView = (SListView) findViewById(R.id.listView);
        mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                AppHttp.getInstance().queryStationInviteOpenRecord();
            }
        });
        mAdapter = new StationInviteHistoryAdapter(null, getContext());
        mListView.setAdapter(mAdapter);
    }

    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case MsgID.query_station_invite_open:
                cancelLoadingDialog();
                onRefreshComplete();
                final ReqResult<StationInviteHistoryBean> result = JSON.parseList(msg.obj, StationInviteHistoryBean.class);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (checkLoginStatus(result)) {
                            mAdapter.setItems(result.getResultList(), true);
                        } else {
                            showToast(result.getMessage());
                        }
                    }
                });
                return true;
            default:
                return super.handleMessage(msg);
        }
    }
}
